1368C - Even Picture - CodeForces Solution


constructive algorithms *1500

Please click on ads to support us..

Python Code:

n = int(input())

inc = 1
f = 1

ans = []

for y in range(n * 2 + 3):
    if y == 0:
        ans += [(x, y) for x in range(3)]

    elif y == n * 2 + 2:
        ans += [(x, y) for x in range(0, 3 * -inc, -inc)]

    else:
        if f == 0:
            ans += [(x, y) for x in range(-2, 3)]

        else:
            ans += [(0, y),  (2 * f, y)]

        if f % 2:
            inc = -inc

        f += inc


print(len(ans))

for i in ans:
    print(*i)


C++ Code:

#include<bits/stdc++.h>
using namespace std;

#define int long long int
#define endl '\n' 

void solve(){
    int n;
    cin>>n;

    cout<<3*n+4<<endl;
    int ind;

    for(int i=0;i<n+1;i++){
        cout<<i<<" "<<i<<endl;
        cout<<i+1<<" "<<i<<endl;
        cout<<i<<" "<<i+1<<endl;
        ind=i;
    }

    cout<<ind+1<<" "<<ind+1<<endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

515A - Drazil and Date
1084B - Kvass and the Fair Nut
1101A - Minimum Integer
985D - Sand Fortress
1279A - New Year Garland
1279B - Verse For Santa
202A - LLPS
978A - Remove Duplicates
1304A - Two Rabbits
225A - Dice Tower
1660D - Maximum Product Strikes Back
1513A - Array and Peaks
1251B - Binary Palindromes
768B - Code For 1
363B - Fence
991B - Getting an A
246A - Buggy Sorting
884A - Book Reading
1180A - Alex and a Rhombus
445A - DZY Loves Chessboard
1372A - Omkar and Completion
159D - Palindrome pairs
981B - Businessmen Problems
1668A - Direction Change
1667B - Optimal Partition
1668B - Social Distance
88B - Keyboard
580B - Kefa and Company
960A - Check the string
1220A - Cards